package com.hatricks.is.common.dto;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.URLUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.net.URL;
import java.util.List;

/**
 * @packageName: com.hatricks.common.dto
 * @className: PageOutDTO
 * @author: yanyuhui
 * @date: 2023/1/8 14:21
 * @description:
 */
@ApiModel(value = "列表出参")
@Data
public class ApiTableProperty<T> {
    public static void main(String[] args) {
        ClassLoader classLoader = ApiTableProperty.class.getClassLoader();
        System.out.println(classLoader);
        URL resource = classLoader.getResource("static/websocket.html");
        URLUtil.getStream(resource);

        System.out.println(resource);
    }

    // 总数据量
    @ApiModelProperty(value = "总数量", name = "total")
    private long total;
    // 明细数据集合
    @ApiModelProperty(value = "明细数据集合", name = "rows")
    private List<T> rows;

    public ApiTableProperty() {

    }

    public ApiTableProperty(long total, List<T> rows) {
        this.total = total;
        this.rows = rows;
    }

    public static <T> ApiTableProperty<T> getList(PageInfo<T> pageInfo) {
        return new ApiTableProperty<>(pageInfo.getTotal(), pageInfo.getList());
    }
}
